package cn.bone.admin.system.loginfo.dao.impl;

import cn.bone.admin.base.dao.impl.BaseDaoImpl;
import cn.bone.admin.system.loginfo.bean.AccessAppLog;
import cn.bone.admin.system.loginfo.dao.IAccessAppLogDao;
import org.mongodb.morphia.query.FindOptions;
import org.mongodb.morphia.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/9/12.
 */
@Repository
public class AccessAppLogDaoImpl extends BaseDaoImpl<AccessAppLog> implements IAccessAppLogDao {


    public List<AccessAppLog> queryList(Integer start, Integer num, String key){

        Query<AccessAppLog> query = this.getDatastore().createQuery(AccessAppLog.class);
        if(!StringUtils.isEmpty(key)){
            query.field("header.method").contains(key);
        }
        FindOptions options = new FindOptions();
        options.skip(start).limit(num);
        query.order("-createTime");
        return query.asList(options);
    }

    public int countQueryList(String key){
        Query<AccessAppLog> query = this.getDatastore().createQuery(AccessAppLog.class);
        if(!StringUtils.isEmpty(key)){
            query.field("header.method").contains(key);
        }
        return (int)query.count();
    }
}
